import { createStore, applyMiddleware } from "redux";
import { createLogger } from "redux-logger";
import { persistStore, persistReducer } from "redux-persist";
import storageSession from "redux-persist/lib/storage/session";
import reducer from "../reducer";
import thunk from "redux-thunk";

const storageConfig = {
  key: "root", // 必须有的
  storage: storageSession, // 缓存机制
  blacklist: ["name", "age"], // reducer 里不持久化的数据,除此外均为持久化数据
};
const myPersistReducer = persistReducer(storageConfig, reducer);
const logger = createLogger();

const enhancer = applyMiddleware(thunk, logger);
const store = createStore(myPersistReducer, enhancer);
export const persistor = persistStore(store);
export default store;
